package org.example.current.customer.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author jie.luo
 * @description
 * @since 2020-06-18
 */
// 指定当前接口为 Feign 接口，name为注册中心注册服务名
@FeignClient(
        name = "provider",
        fallback = CurrentProviderClient.ProviderFallback.class
)
public interface CurrentProviderClient {

    String CONTEXT_PATH = "/provider";

    @GetMapping(CONTEXT_PATH + "/user")
    String getUserName(@RequestParam(name = "userId") Integer id);

    @GetMapping(CONTEXT_PATH + "/users")
    String getUsers();

    @Component
    class ProviderFallback implements CurrentProviderClient {

        @Override
        public String getUserName(Integer id) {
            System.out.println("服务熔断了。。。。。。");
            return "服务熔断";
        }

        @Override
        public String getUsers() {
            return "服务熔断......";
        }
    }
}
